package com.example.demo;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {
    //参数检验
    @RequestMapping("/check")
    public  boolean checkLogin(String userName, String password, HttpSession session){
        //直接使用sprig集成比较方法
        System.out.println("用户名："+userName);
        if(!StringUtils.hasLength(userName)&& !StringUtils.hasLength(password)){
            return false;
        }
        if("admin".equals(userName)&&"123456".equals(password)){
            //密码和用户名正确的话的，直接分配一个session
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }
    @RequestMapping("/index")
    public String index(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return userName;
    }
}
